package eerbaar.action.internal.lib;

import java.util.Map;

import eerbaar.context.IContext;
import eerbaar.context.IParams;
import eerbaar.context.ParamFactory;
import eerbaar.shared.message.Message;
import eerbaar.shared.message.MsgHelper;

public class SendMessageAction extends AbstractAction {

    private String name;

    private IParams params;

    public SendMessageAction() {
        super("sendMessage");
        this.params = ParamFactory.createParams();

    }

    public SendMessageAction(IParams params) {
        super("sendMessage");
        this.params = params;

        setup(params);
    }

    @Override
    public void execute(IContext model) {

        MsgHelper.sendMsg(this.name, new Message());
    }

    @Override
    public void execute(IContext model, Map<String, String> map) {
        execute(model);
    }

    @Override
    public String[] getParamNames() {

        return new String[] {};
    }

    @Override
    public IParams getParams() {

        return this.params;
    }

    @Override
    public void setParams(IParams params) {
        this.params = params;
        setup(params);
    }

    private void setup(IParams params) {

        this.name = params.get("name");
    }
}
